package com.zhuang.controller;

import com.zhuang.exception.CustomizeErrorCode;
import com.zhuang.exception.CustomizeException;
import com.zhuang.pojo.User;
import com.zhuang.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

@Controller
public class NotificationController {

    @Autowired
    NotificationService notificationService;

    @GetMapping("/notification")
    public String updateStatus(@RequestParam(name = "questionId") Integer questionId,
                               @RequestParam(name = "notificationId") Integer notificationId,
                               HttpSession session) {

        User user = (User) session.getAttribute("user");
        if (user == null) {
            throw new CustomizeException(CustomizeErrorCode.NOT_LOGIN);
        }
        notificationService.updateStatus(notificationId);
        return "redirect:/question/"+questionId;
    }

}
